package com.atguigu.gmall.realtime.util;

/**
 * @Author lzc
 * @Date 2022/4/30 10:36
 */
public class SQLUtil {
    public static String getKafkaDDL(String groupId, String topic) {
        return
            "with(" +
                "   'connector' = 'kafka', " +
                "   'properties.bootstrap.servers' = 'hadoop162:9092,hadoop163:9092,hadoop164:9092', " +
                "   'properties.group.id' = '" + groupId + "', " +
                "   'topic' = '" + topic + "', " +
                "   'format' = 'json', " +
                "   'scan.startup.mode' = 'latest-offset' " +
                ")";
    }
    
    
    public static String getBaseDicLookUpDDL() {
        
        return "create table `base_dic`( " +
            "`id` string, " +
            "`dic_name` string, " +
            "`parent_code` string, " +
            "`create_time` timestamp, " +
            "`operate_time` timestamp, " +
            "primary key(`id`) not enforced " +
            ")" + mysqlLookUpTableDDL("base_dic");
    }
    
    public static String mysqlLookUpTableDDL(String tableName) {
        
        return "with ( " +
            "'connector' = 'jdbc', " +
            "'url' = 'jdbc:mysql://hadoop162:3306/gmall2022?useSSL=false', " +
            "'table-name' = '" + tableName + "', " +
            "'lookup.cache.max-rows' = '50', " +
            "'lookup.cache.ttl' = '1 hour', " +
            "'username' = 'root', " +
            "'password' = 'aaaaaa', " +
            "'driver' = 'com.mysql.cj.jdbc.Driver' " +
            ")";
    }
    
    public static String getUpsertKafkaDDL(String topic) {
        return "with ( " +
            "  'connector' = 'upsert-kafka', " +
            "  'topic' = '" + topic + "', " +
            "  'properties.bootstrap.servers' = 'hadoop162:9092,hadoop163:9092', " +
            "  'key.format' = 'json', " +
            "  'value.format' = 'json' " +
            ")";
    }
}
